/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package editor.impl;

import editor.EditorPackage;
import editor.Node;
import editor.Occurrence;
import editor.Relationship;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Relationship</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link editor.impl.RelationshipImpl#getOccurrence <em>Occurrence</em>}</li>
 *   <li>{@link editor.impl.RelationshipImpl#getSourceRelationship <em>Source Relationship</em>}</li>
 *   <li>{@link editor.impl.RelationshipImpl#getTargetRelationship <em>Target Relationship</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RelationshipImpl extends EObjectImpl implements Relationship {
	/**
   * The default value of the '{@link #getOccurrence() <em>Occurrence</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getOccurrence()
   * @generated
   * @ordered
   */
	protected static final Occurrence OCCURRENCE_EDEFAULT = Occurrence.ONE_AND_ONLY_ONE;

	/**
   * The cached value of the '{@link #getOccurrence() <em>Occurrence</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getOccurrence()
   * @generated
   * @ordered
   */
	protected Occurrence occurrence = OCCURRENCE_EDEFAULT;

	/**
   * The cached value of the '{@link #getSourceRelationship() <em>Source Relationship</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getSourceRelationship()
   * @generated
   * @ordered
   */
	protected Node sourceRelationship;

	/**
   * The cached value of the '{@link #getTargetRelationship() <em>Target Relationship</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getTargetRelationship()
   * @generated
   * @ordered
   */
	protected Node targetRelationship;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected RelationshipImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return EditorPackage.Literals.RELATIONSHIP;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Occurrence getOccurrence() {
    return occurrence;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setOccurrence(Occurrence newOccurrence) {
    Occurrence oldOccurrence = occurrence;
    occurrence = newOccurrence == null ? OCCURRENCE_EDEFAULT : newOccurrence;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.RELATIONSHIP__OCCURRENCE, oldOccurrence, occurrence));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Node getSourceRelationship() {
    if (sourceRelationship != null && sourceRelationship.eIsProxy())
    {
      InternalEObject oldSourceRelationship = (InternalEObject)sourceRelationship;
      sourceRelationship = (Node)eResolveProxy(oldSourceRelationship);
      if (sourceRelationship != oldSourceRelationship)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP, oldSourceRelationship, sourceRelationship));
      }
    }
    return sourceRelationship;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Node basicGetSourceRelationship() {
    return sourceRelationship;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetSourceRelationship(Node newSourceRelationship, NotificationChain msgs) {
    Node oldSourceRelationship = sourceRelationship;
    sourceRelationship = newSourceRelationship;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP, oldSourceRelationship, newSourceRelationship);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setSourceRelationship(Node newSourceRelationship) {
    if (newSourceRelationship != sourceRelationship)
    {
      NotificationChain msgs = null;
      if (sourceRelationship != null)
        msgs = ((InternalEObject)sourceRelationship).eInverseRemove(this, EditorPackage.NODE__OUTGOING_NODE, Node.class, msgs);
      if (newSourceRelationship != null)
        msgs = ((InternalEObject)newSourceRelationship).eInverseAdd(this, EditorPackage.NODE__OUTGOING_NODE, Node.class, msgs);
      msgs = basicSetSourceRelationship(newSourceRelationship, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP, newSourceRelationship, newSourceRelationship));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Node getTargetRelationship() {
    if (targetRelationship != null && targetRelationship.eIsProxy())
    {
      InternalEObject oldTargetRelationship = (InternalEObject)targetRelationship;
      targetRelationship = (Node)eResolveProxy(oldTargetRelationship);
      if (targetRelationship != oldTargetRelationship)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP, oldTargetRelationship, targetRelationship));
      }
    }
    return targetRelationship;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Node basicGetTargetRelationship() {
    return targetRelationship;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetTargetRelationship(Node newTargetRelationship, NotificationChain msgs) {
    Node oldTargetRelationship = targetRelationship;
    targetRelationship = newTargetRelationship;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP, oldTargetRelationship, newTargetRelationship);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setTargetRelationship(Node newTargetRelationship) {
    if (newTargetRelationship != targetRelationship)
    {
      NotificationChain msgs = null;
      if (targetRelationship != null)
        msgs = ((InternalEObject)targetRelationship).eInverseRemove(this, EditorPackage.NODE__INCOMING_NODE, Node.class, msgs);
      if (newTargetRelationship != null)
        msgs = ((InternalEObject)newTargetRelationship).eInverseAdd(this, EditorPackage.NODE__INCOMING_NODE, Node.class, msgs);
      msgs = basicSetTargetRelationship(newTargetRelationship, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP, newTargetRelationship, newTargetRelationship));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP:
        if (sourceRelationship != null)
          msgs = ((InternalEObject)sourceRelationship).eInverseRemove(this, EditorPackage.NODE__OUTGOING_NODE, Node.class, msgs);
        return basicSetSourceRelationship((Node)otherEnd, msgs);
      case EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP:
        if (targetRelationship != null)
          msgs = ((InternalEObject)targetRelationship).eInverseRemove(this, EditorPackage.NODE__INCOMING_NODE, Node.class, msgs);
        return basicSetTargetRelationship((Node)otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP:
        return basicSetSourceRelationship(null, msgs);
      case EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP:
        return basicSetTargetRelationship(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case EditorPackage.RELATIONSHIP__OCCURRENCE:
        return getOccurrence();
      case EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP:
        if (resolve) return getSourceRelationship();
        return basicGetSourceRelationship();
      case EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP:
        if (resolve) return getTargetRelationship();
        return basicGetTargetRelationship();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case EditorPackage.RELATIONSHIP__OCCURRENCE:
        setOccurrence((Occurrence)newValue);
        return;
      case EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP:
        setSourceRelationship((Node)newValue);
        return;
      case EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP:
        setTargetRelationship((Node)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case EditorPackage.RELATIONSHIP__OCCURRENCE:
        setOccurrence(OCCURRENCE_EDEFAULT);
        return;
      case EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP:
        setSourceRelationship((Node)null);
        return;
      case EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP:
        setTargetRelationship((Node)null);
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case EditorPackage.RELATIONSHIP__OCCURRENCE:
        return occurrence != OCCURRENCE_EDEFAULT;
      case EditorPackage.RELATIONSHIP__SOURCE_RELATIONSHIP:
        return sourceRelationship != null;
      case EditorPackage.RELATIONSHIP__TARGET_RELATIONSHIP:
        return targetRelationship != null;
    }
    return super.eIsSet(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (occurrence: ");
    result.append(occurrence);
    result.append(')');
    return result.toString();
  }

} //RelationshipImpl
